package com.smartsaas.ugclivii.handler;

import com.smartsaas.ugclivii.cd.DesignTreeAskEditControlHandler;
import com.smartsaas.ugclivii.cd.EleTreeSelectHandler;
import com.smartsaas.ugclivii.cd.MlTreeSelectHandler;
import com.smartsaas.ugclivii.entity.BomConfig;
import com.smartsaas.ugclivii.job.JobRunUtils;
import com.smartsaas.ugclivii.job.JobUtils;
import com.smartsaas.ugclivii.loader.JsonLoader;
import com.smartsaas.ugclivii.ui.UiContext;
import com.smartsaas.ugclivii.utils.FunUtils;
import nxopen.NXException;
import nxopen.NXMessageBox;
import nxopen.blockstyler.BlockDialog;
import nxopen.blockstyler.Toggle;
import nxopen.blockstyler.UIBlock;

import java.rmi.RemoteException;

public class UpdateImpl implements BlockDialog.Update {
    @Override
    public int update(UIBlock uiBlock) throws NXException, RemoteException {
        if (uiBlock==UiContext.getInstance().getLayerHidden()){
            JobUtils.doJob("加载图层",JobUtils::loadLayer);
        }
        if (UiContext.getInstance().getMlSelection()==uiBlock){
            FunUtils.clearTree(UiContext.getInstance().getMlTree());
            JobUtils.doJob("选择模料",JobUtils::loadMl);
        }
        if (UiContext.getInstance().getMlCsy()==uiBlock){
            JobUtils.doJob("计算尺寸",MlTreeSelectHandler::getBodyDistances);
        }
        if(UiContext.getInstance().getEleSelection()==uiBlock){
            FunUtils.clearTree(UiContext.getInstance().getEleTree());
            JobUtils.doJob("选择电极",JobUtils::loadEle);
        }
        if (UiContext.getInstance().getEleCsy()==uiBlock){
            JobUtils.doJob("计算尺寸", EleTreeSelectHandler::getBodyDistances);
        }
        if (UiContext.getInstance().getBomSelection()==uiBlock){
            JobUtils.doJob("选择BOM", JobUtils::loadBom);
        }
        if(UiContext.getInstance().getMlUpload()==uiBlock){
            JobUtils.doJob("上传模料", JobRunUtils::uploadMl);

        }
        if(UiContext.getInstance().getEleUploadButton()==uiBlock){
            JobUtils.doJob("上传电极",JobRunUtils::uploadEle);
        }
        if (UiContext.getInstance().getWcsAuto()==uiBlock){
            //设置组件失活
            boolean value = UiContext.getInstance().getWcsAuto().value();
            UiContext.getInstance().getMlCsy().setEnable(!value);
            UiContext.getInstance().getBomCsy().setEnable(!value);
            UiContext.getInstance().getEleCsy().setEnable(!value);
        }
        return 0;
    }

    public void echo(String title,String[] sl){
        for (String s : sl ){
            UiContext.getInstance().debug("【"+title+"】："+s);
        }
    }
}
